<div class="system-messages">
    <ul>
        <?php
        $messages = $this->messages;
        foreach ($messages as $message) :
            ?>
            <li><?= $message ?></li>
        <?php
        endforeach
        ?>
    </ul>
</div>
<div>
    <div class="admin-search-n-filter">
        <div class="admin-search">
            <label><input type="text" value="<?= $this->enteredKeyWords ?>"/></label>
            <input type="button" value=""/>
        </div>
        <div class="admin-hyperlink-btn">
            <a href="/classico/public/admin/productType/index">
                Refresh
            </a>
        </div>
    </div>
</div>
<div>
    <div class="datagrid">
        <table>
            <tr>
                <th width="2%"><label><input id="check-box-all" type="checkbox"/></label></th>
                <th width="2%">ID</th>
                <th width="10%">Name</th>
                <th width="65%">Description</th>
                <th>Number Of Products</th>
                <th width="5%" class="center">Delete</th>
            </tr>
            <?php
            $productTypes = $this->productTypes;
            foreach ($productTypes as $index => $productType) :
                ?>
                <tr class="<?= ($index % 2 == 0) ? 'alt' : '' ?>">
                    <td>
                        <label>
                            <input class="check-box-product-type-id" type="checkbox"
                                   value="<?= $productType['ID'] ?>"/>
                        </label>
                    </td>
                    <td><?= $productType['ID'] ?></td>
                    <td>
                        <a href="/classico/public/admin/productType/update/productTypeID/<?= $productType['ID'] ?>">
                            <?= $productType['Name'] ?>
                        </a>
                    </td>
                    <td><?= $productType['Description'] ?></td>
                    <td><?= $productType['NumberOfProducts'] ?></td>
                    <td class="center">
                        <div class="enabled-delete-icon tool-icon"></div>
                        <form action="/classico/public/admin/productType/delete" method="post">
                            <input type="hidden" name="isPost" value=""/>
                            <input type="hidden" name="productTypeIDs[]" value="<?= $productType['ID'] ?>"/>
                        </form>
                    </td>
                </tr>
            <?php
            endforeach
            ?>
        </table>
    </div>
</div>
<?= $this->paginationControl($this->paginator, 'Sliding', 'my_pagination_control.phtml') ?>
<script type="text/javascript">
    $('#tool-btn-confirm, #tool-btn-unblock, #tool-btn-block')
        .removeClass('enabled-tool-btn');
    $('#tool-btn-confirm > div')
        .removeClass('enabled-confirm-icon')
        .addClass('disabled-confirm-icon');
    $('#tool-btn-unblock > div')
        .removeClass('enabled-unblock-icon')
        .addClass('disabled-unblock-icon');
    $('#tool-btn-block > div')
        .removeClass('enabled-block-icon')
        .addClass('disabled-block-icon');
</script>
<script type="text/javascript">
    function forwardHyperlink() {
        var currentURL = window.location.href;

        var forwardURL = currentURL.replace(/\/productType\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/index\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/keyWords\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/page\/[\w\W]*/, '');

        forwardURL += '/productType/index';

        var keyWords = $('.admin-search input[type = "text"]').val();
        if (keyWords != '') {
            forwardURL += '/keyWords/' + keyWords;
        }

        window.location.href = forwardURL;
    }

    $('.admin-search input[type = "text"]').keydown(function (event) {
        if (event.which == 13) {
            forwardHyperlink();
        }
    });

    $('.admin-search input[type = "button"]').click(function () {
        forwardHyperlink();
    });
</script>
<script type="text/javascript">
    $('#check-box-all').click(function () {
        if ($(this).attr('checked')) {
            $('.check-box-product-type-id').attr('checked', true);
        } else {
            $('.check-box-product-type-id').attr('checked', false);
        }
    });

    $('.datagrid .tool-icon').click(function () {
        $(this).parent(null).find('form').submit();
    });
</script>
<script type="text/javascript">
    $('#tool-btn-delete.enabled-tool-btn').click(function () {
        var form = $(this).find('form');

        var checkBoxes = $('.check-box-product-id:checked');
        for (var i = 0; i < checkBoxes.length; i++) {
            var productTypeID = checkBoxes[i].value;
            var tag = '<input type="hidden" name="productTypeIDs[]" value="' + productTypeID + '"/>';
            form.append(tag);
        }

        form.submit();
    });

    $('#tool-btn-update.enabled-tool-btn').click(function () {
        var checkedCheckBoxes = $('.check-box-product-type-id:checked');
        var productTypeID = checkedCheckBoxes[0].value;
        location.href = '/classico/public/admin/productType/update/productTypeID/' + productTypeID;
    });
</script>